<?php
namespace Admin\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        if (!empty($_POST)) {
            $email = stripslashes(trim($_POST['email']));
            $User = M('user');
            $user = $User->field('id, username, password')->where("email = '" . $email . "'")->select();

            if (empty($user)) {//该邮箱尚未注册！
                echo '该邮箱尚未注册';
                exit;
            } else {
                $uid = $user['id'];
                $token = md5($user['username'] . $user['password']);
                $url = "http://localhost/train_08/index.php/Admin/Reset/reset?email=" . $email . "&token=" . $token;
                $time = "忘记密码？";
                $result = sendMail($email, $time, $url);
                if ($result) {//邮件发送成功
                    $msg = '系统已向您的邮箱发送了一封邮件<br/>请登录到您的邮箱及时重置您的密码！';
                } else {
                    $msg = "gg";
                }
                echo $msg;
            }
        } else {
            $this->display();
        }
    }

    public function addUser()
    {
        if (!empty($_POST)) {
            $username = $_POST['username'];
            $password1 = $_POST['password'];
            $repassword1 = $_POST['repassword'];
            $email = $_POST['email'];
            if ($password1 == $repassword1) {
                $password = md5($password1);
                $User = M('user');
                $user['username'] = $username;
                $user['password'] = $password;
                $user['email'] = $email;
                $result = $User->add($user);
                if ($result) {
                    $this->success('hahaha');
                } else {
                    $this->error('gg');
                }
            } else {
                echo '两次密码不一致！';
            }
        } else {
            $this->display();
        }
    }

    /*    public function index()
        {
            $result = sendMail('969128101@qq.com', 'email modify', 'hahahahaha');
            if ($result) {
                echo 'hahahahaha';
            } else {
                echo 'gg';
            }
        }*/
}

?>